
from tkinter import * 

class MenuDemo:
	def hello(self):
		print("hello!")
		
	def __init__(self):
		window = Tk()
		window.title("菜单演示")
		menubar = Menu(window)       #定义菜单条
		window.config(menu = menubar)
		
		#创建下拉菜单，并添加到菜单条 
		operationMenu = Menu(menubar, tearoff = 0)  #在菜单条中定义“操作”菜单
		menubar.add_cascade(label = "操作", menu = operationMenu)
		operationMenu.add_command(label = "加", command = self.add)#在菜单添加菜单项 
		operationMenu.add_command(label="减", command=self.subtract) 
		operationMenu.add_separator()   #菜单项的分隔符 
		operationMenu.add_command(label = "乘", command = self.multiply) 
		operationMenu.add_command(label="除", command=self.divide) 
		
		exitMenu = Menu(menubar, tearoff = 0)  #在菜单条中定义“退出”菜单
		menubar.add_cascade(label = "退出", menu = exitMenu) 
		exitMenu.add_command(label = "退出", command = window.quit) 
		
		mainloop() 
		
	def add(self):
		print("相加")
	def subtract(self):
		print("相减")
	def multiply(self):
		print("相乘")
	def divide(self):
		print("相除")
		
MenuDemo() 

